import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * 项目名称：wangxu
 * 类 名 称：hw735 行星碰撞
 * 描 述：
 * 创建时间：2023/1/30 8:37 下午
 * 创 建 人：wang-xu
 */
public class hw735 {
    public static void main(String[] args) {
        int[] asteroids ={8,-8};
        asteroidCollision(asteroids);
    }

    public static int[] asteroidCollision(int[] asteroids) {
        Stack<Integer> stack = new Stack<>();
        for (int i=0;i<asteroids.length;i++) {
            boolean isExist = true;
            // 发生碰撞的条件
            while (isExist && asteroids[i] < 0 && !stack.isEmpty() && stack.peek() > 0) {
                isExist = stack.peek() < -asteroids[i];
                if (stack.peek() <= -asteroids[i]) {
                    stack.pop();
                }
            }
            if (isExist) {
                stack.push(asteroids[i]);
            }
        }

        int[] ans = new int[stack.size()];
        for (int i = stack.size() - 1; i >= 0; i--) {
            ans[i] = stack.pop();
        }
        return ans;
    }

}


